<!-- <title>瑞众银保“五个一”功成--营业部经理一季一启动记录<title> -->
<style lang="less" scoped>
@import '@css/list.less';
</style>

<template>
  <div id="app">
    <van-sticky>
      <div class="title">营业部经理一季一启动记录</div>
    </van-sticky>
    <div
      style="margin: 20px auto; text-align: center"
      v-if="ManagerSeasonalStartRecordList.length == 0"
    >
      暂无数据
    </div>
    <van-collapse
      v-model="activeNames"
      accordion
      v-for="(item, index) of ManagerSeasonalStartRecordList"
      :key="index"
    >
      <van-collapse-item
        :title="`${index + 1}:${item.fileName ? item.fileName : '图片'}`"
        :label="item.createDate"
        :name="index"
      >
        <van-form>
          <van-cell-group inset>
            <div v-if="item.fileName">
              <van-cell title="点击可下载文件" :value="item.fileName" :url="item.fileUrl" is-link />
            </div>
            <div v-else>
              <van-field :name="`fileUrl${index}`" label="文件">
                <template #input>
                  <van-uploader
                    :deletable="false"
                    v-model="item.uploaderImgList"
                    :max-count="1"
                  ></van-uploader>
                </template>
              </van-field>
            </div>
          </van-cell-group>
        </van-form>
      </van-collapse-item>
    </van-collapse>
  </div>
</template>
<script setup>
import {
  onBeforeMount,
  onMounted,
  onUnmounted,
  watch,
  computed,
  provide,
  inject,
  ref,
  reactive,
  nextTick,
  h
} from 'vue'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
const route = useRoute()
const dayjs = inject('$dayjs')
const showPageLoading = inject('showPageLoading')
const hidePageLoading = inject('hidePageLoading')
const showAllNonBaseMenuItem = inject('showAllNonBaseMenuItem')
const hideAllNonBaseMenuItem = inject('hideAllNonBaseMenuItem')
import { isIOS, parseTime, handleFontSize } from '@/utils'
import { yb51_sales_manager_seasonal_start_record_yb51SalesManagerSeasonalStartRecordList } from '@/request/api.js'
//生命周期

onMounted(() => {
  agentcode = route.query.agentcode
  weeks = route.query.weeks
  getManagerSeasonalStartRecordList()
})
//生命周期

let agentcode
let weeks

const activeNames = ref(['1'])
//获取经理最近三天拜访记录列表
const ManagerSeasonalStartRecordList = ref([])

function getManagerSeasonalStartRecordList() {
  showPageLoading()
  let params = new FormData()
  params.append('agentCode', agentcode)
  params.append('week', weeks)

  yb51_sales_manager_seasonal_start_record_yb51SalesManagerSeasonalStartRecordList(params).then(
    (r) => {
      hidePageLoading()
    if (r.status == 200) {
        ManagerSeasonalStartRecordList.value = r.data.map((item) => {
          if (isImageFile(item.fileUrl)) {
            // 使用正则表达式判断文件扩展名是否为图片格式
            item['uploaderImgList'] = [{ url: item.fileUrl }]
            return item
          } else {
            item['fileName'] = parseFileName(item.fileUrl) // 获取链接中的文件名部分
            return item
          }
        })
       
      } else {
        console.log('出错了，请重试')
        alert('出错了，请重试')
      }
    }
  )
}

function parseFileName(url) {
  // 获取链接中的文件名部分
  var fileName = url.substring(url.lastIndexOf('/') + 1)
  // 如果文件名还包含有查询参数（例如 ?key=value），需要去掉查询参数部分
  if (fileName.indexOf('?') !== -1) {
    fileName = fileName.substring(0, fileName.indexOf('?'))
  }
  return fileName
}
function isImageFile(url) {
  // 使用正则表达式判断文件扩展名是否为图片格式
  var imageExtensions = /\.(gif|jpe?g|tiff?|png|webp|bmp)$/i
  return imageExtensions.test(url)
}
</script>
